package StudyCode.summary.zipfile;

import java.io.IOException;
import java.io.InputStream;
import java.io.PushbackInputStream;
import java.util.zip.GZIPInputStream;

/**
 * 版权所有 科技与人文(www.tah1986.com)
 */
public class ChecksInputStreamIsGzipped {
	public static InputStream decompressStream(InputStream input)
			throws IOException {
		PushbackInputStream pb = new PushbackInputStream(input, 2);
		byte[] signature = new byte[2];
		pb.read(signature);
		pb.unread(signature);
		if (signature[0] == (byte) 0x1f && signature[1] == (byte) 0x8b) {
			return new GZIPInputStream(pb);
		} else {
			return pb;
		}
	}
}
